<template>
  <div class="cinema_body">
    <Loading v-if="state.isLoading"/>
    <Scroller v-else ref="city_list">
      <ul>
        <li v-for="item in state.cinemaList" :key="item.id">
          <div>
            <span>{{ item.nm }}</span>
            <span class="q"><span class="price">{{ item.sellprice }}</span> 元起</span>
          </div>
          <div class="address">
            <span>{{ item.addr }}</span>
            <span>{{ item.distance }}</span>
          </div>
          <div class="card">
            <div v-if="item.tag.allowrefund===1" :class="formatClass5(item.tag.allowrefund)">{{
                format1(item.tag.allowrefund)
              }}
            </div>
            <div v-if="item.tag.endorse===1" :class="formatClass5(item.tag.endorse)">{{ format2(item.tag.endorse) }}</div>
            <div v-if="item.tag.sell===1" :class="formatClass6(item.tag.sell)">{{ format3(item.tag.sell) }}</div>
            <div v-if="item.tag.snack===1" :class="formatClass6(item.tag.snack)">{{ format4(item.tag.snack) }}</div>
            <!--<div v-for="(num,key) in item.tag" :key="key">{{ key | formatCard }}</div>-->
          </div>
        </li>
      </ul>
    </Scroller>
  </div>
</template>

<script>
import {toRefs, reactive, getCurrentInstance, onActivated,} from "vue";

export default {
  name: "CiListBrand",
  setup() {
    const state = reactive({
      cinemaList: [],
      isLoading: true,
      prevCityId: -1

    });
    let {proxy} = getCurrentInstance()
    onActivated(() => {
      const cityId = proxy.$store.state.city.id;
      if (proxy.prevCityId === cityId) {
        return;
      }
      proxy.isLoading = true;
      proxy.$axios.get('/api/cinemaList?cityid=' + cityId).then((res) => {
        const msg = res.data.msg;
        if (msg === '成功') {
          proxy.cinemaList = res.data.data;
          proxy.isLoading = false;
          proxy.prevCityId = cityId;
        }
      });
    });

    return {
      state, ...toRefs(state), proxy,
    }
  },
  data() {
    return {}
  },
  methods: {
    format1(key){
      if (key === 1) {
        return '改签';
      }
    },
    format2(key){
      if (key === 1) {
        return '退';
      }
    },
    format3(key){
      if (key === 1) {
        return '折扣卡';
      }
    },
    format4(key){
      if (key === 1) {
        return '小吃卡';
      }
    },
    formatClass5(key){
      if (key === 1) {
        return 'bl';
      }
    },
    formatClass6(key){
      if (key === 1) {
        return 'or';
      }
    },

  },
  components: {},
}
</script>

<style scoped>
.cinema_body {
  flex: 1;
  overflow: auto;
}

.cinema_body ul {
  padding: 20px;
}

.cinema_body li {
  border-bottom: 1px solid #e6e6e6;
  margin-bottom: 20px;
}

.cinema_body div {
  margin-bottom: 10px;
}

.cinema_body .q {
  font-size: 11px;
  color: #f03d37;
}

.cinema_body .price {
  font-size: 18px;
}

.cinema_body .address {
  font-size: 13px;
  color: #666;
}

.cinema_body .address span:nth-of-type(2) {
  float: right;
}

.cinema_body .card {
  display: flex;
}

.cinema_body .card div {
  padding: 0 3px;
  height: 15px;
  line-height: 15px;
  border-radius: 2px;
  color: #f90;
  border: 1px solid #f90;
  font-size: 13px;
  margin-right: 5px;
}

.cinema_body .card div.or {
  color: #f90;
  border: 1px solid #f90;
}

.cinema_body .card div.bl {
  color: #589daf;
  border: 1px solid #589daf;
}
</style>